package com.sfac.springBoot.modules.test.controller;

import com.github.pagehelper.PageInfo;
import com.sfac.springBoot.modules.common.vo.Result;
import com.sfac.springBoot.modules.common.vo.Search;
import com.sfac.springBoot.modules.test.entity.City;
import com.sfac.springBoot.modules.test.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class CityController {
    @Autowired
    private CityService cityService;
    @PostMapping(value = "/insert",consumes = "application/json")
    public Result<City> insertCity(@RequestBody City city){
        return cityService.insert(city);
    }
    @PutMapping(value = "/update",consumes = "application/x-www-form-urlencoded")
    public Result<City> update(@ModelAttribute City city){
        return cityService.update(city);
    }
    @DeleteMapping(value = "/delete/{cityId}")
    public Result<Object> delete(@PathVariable int cityId){
        return cityService.delete(cityId);
    }
    @GetMapping(value = "/query1/{cityId}")
    public City query1(@PathVariable int cityId){
        return cityService.queryById1(cityId);
    }
    @GetMapping(value = "/query2/{cityId}")
    public List<City> query2(@PathVariable int cityId){
        return cityService.queryById2(cityId);
    }
    @PostMapping(value = "/query3",consumes = "application/json")
    public PageInfo<City> query3(@RequestBody Search search){
        return cityService.queryById3(search);
    }
}
